#!/bin/bash
OK=0
WARN=1
CRITICAL=2
UNKNOWN=3
PATH="/bin:/sbin:/usr/bin:/usr/sbin"

Ok_name=''
Fail_name=''
Judge=0
TTimeout=6
HName=`/bin/hostname -s`

function timeout_df() {
		#echo $choice start
                /usr/bin/timeout 1 /usr/lib64/nagios/plugins/check_mount_strace touch /$2 1>/dev/null 2>&1
                /usr/bin/timeout $TTimeout /usr/lib64/nagios/plugins/check_mount_strace test -$1 /$2 1>/dev/null 2>&1
		#continue

                if [ $? != 0  ]
                then
                        Judge=1
                        Fail_name="${Fail_name} ${choice}"
		else
			Ok_name="${Ok_name} ${choice}"
                fi
		#echo $choice end
}



if [ -e /etc/init.d/lustre ]
then

Lmount=`cat /etc/init.d/lustre  |grep "nms check"|awk -F : '{print $2}'`
#for choice in besfs bes3fs publicfs besfs2 dybfs scratchfs workfs cefs             
        ###
for choice in $Lmount
do
	case $choice in
	besfs)						   ###
		timeout_df  w "$choice/nms/$HName" 
		;;

	bes3fs)
		timeout_df  w "$choice/nms/$HName" 
                ;;

        besfs2)
		timeout_df  w "$choice/nms/$HName" 
                ;;

	publicfs)
		timeout_df  w "$choice/nms/$HName" 
		;;

        dybfs)
		timeout_df  w "$choice/nms/$HName" 
                ;;

        scratchfs)
		timeout_df  w "$choice/cc/nagios/$HName" 
                ;;

        workfs)
		timeout_df  r "$choice/cc/nagios/testfs" 
                ;;

        cefs)
		timeout_df  w "$choice/nms/$HName" 
                ;;

	esac

done

if [ $Judge -eq 1 ]
then
	echo "$Fail_name  wrong"
	exit $CRITICAL
else
	echo " $Ok_name are OK "
	exit $OK
fi

else
	echo "can not find file /etc/init.d/lustre"
	exit $CRITICAL
fi
